package com.climber.spb_rabbitmq.exchange;

import com.climber.spb_rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;

public class PulisherDirect {
    private static final String EXCHANGE_NAME = "logs2";

    public static void main(String[] args) {
        try (Channel channel = RabbitMQUtils.getChannel()) {
//            fanout 所有该队列相应的消费者都能接受
            channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
            ArrayList<String> numberMessage = new ArrayList<>();
            numberMessage.add("1");
            numberMessage.add("2");
            numberMessage.add("3");
            for (String s : numberMessage) {
                channel.basicPublish(EXCHANGE_NAME, "number", null, s.getBytes(StandardCharsets.UTF_8));
            }
            ArrayList<String> charMessage = new ArrayList<>();
            charMessage.add("q");
            charMessage.add("d");
            charMessage.add("g");
            for (String s : charMessage) {
                channel.basicPublish(EXCHANGE_NAME, "character", null, s.getBytes(StandardCharsets.UTF_8));
            }
        } catch (Exception e) {
        }
    }
}


